
from typing import Optional
from pydantic import BaseModel

class DepartmentCreate(BaseModel):
    name: str
    location: str

    def check(self):
        if not 0 < len(self.name) < 50:
            raise ValueError("Department name must be between 0 and 50 characters.")
        if not 0 < len(self.location) < 100:
            raise ValueError("Location must be between 0 and 100 characters.")

class DepartmentUpdate(BaseModel):
    name: Optional[str] = None
    location: Optional[str] = None

    def check(self):
        if self.name is not None and not 0 < len(self.name) < 50:
            raise ValueError("Department name must be between 0 and 50 characters.")
        if self.location is not None and not 0 < len(self.location) < 100:
            raise ValueError("Location must be between 0 and 100 characters.")